package com.shuorikeji.huohuo.view;

import android.view.View;

import androidx.annotation.NonNull;

public class VerticalPageTransformer extends BasePageTransformer {
    private static final float MIN_SCALE = 0.85f;

    @Override
    public void transformPage(@NonNull View page, float position) {
        resetTransform(page);
        int pageWidth = page.getWidth();

        if (position < -1) { // [-Infinity,-1)
            page.setAlpha(0f);
        } else if (position <= 0) { // [-1,0]
            page.setAlpha(1f);
            page.setTranslationX(0f);
            page.setScaleX(1f);
            page.setScaleY(1f);
        } else if (position <= 1) { // (0,1]
            page.setAlpha(1 - position);
            page.setTranslationX(pageWidth * -position);
            float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position));
            page.setScaleX(scaleFactor);
            page.setScaleY(scaleFactor);
        } else { // (1,+Infinity]
            page.setAlpha(0f);
        }
    }
}
